﻿using System;

class BinaryToDecimal
{
    static void Main()
    {
        //Exercise 2.
        //Write a program to convert binary numbers to their decimal representation.
        //For example: 111110100 -> 500

        Console.Write("Enter a binary number: ");        
        string numberStr = Console.ReadLine();        
        int number = int.Parse(numberStr);
        
        int[] array = new int[numberStr.Length];
        for (int i = 0; i < numberStr.Length; i++)
        {
            array[i] = number % 10;
            number = number / 10;
        }

        int result = 0;
        for (int i = 0; i < numberStr.Length; i++)
        {
            result = result + (int)(array[i] * Math.Pow(2, i));
        }
        
        Console.WriteLine(result);       

    }
}

